<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="com.yls.except.util.StringIsempty" %>
<%@ page import="com.yls.except.util.ImgProperties" %>
<%@ page import="com.yls.except.util.HexString" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    String url = request.getHeader("Referer");
    if (!StringIsempty.isallempty(url))
        url = url.replace(basePath.replace(path + "/", ""), "");
    String item = ImgProperties.getConstan("itemname");
    Cookie namecookie = new Cookie("token", "");
    namecookie.setMaxAge(0);
    namecookie.setPath("/" + item);
    response.addCookie(namecookie);
    namecookie = new Cookie("type", "0");
    namecookie.setMaxAge(0);
    namecookie.setPath("/" + item);
    response.addCookie(namecookie);
    namecookie = new Cookie("invitecode", "");
    namecookie.setMaxAge(0);
    namecookie.setPath("/" + item);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>登录</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="js/public.js"></script>
    <script type="text/javascript">
        $(function () {
            var token = $("#tokne").val();
            if(!isempty(token)) {
                <%
                    if(!StringIsempty.isallempty(url)) {
                %>
                    location.href = "<%=url%>";
                <%
                    } else {
                %>
                    location.href = "/except/files/home_page.jsp";
                <%
                    }
                %>
            }
//                location.href = "/except/files/shop_page.jsp";
        });
        function login() {
            var openid = $("#openid").val();
            var url = "/except/usercontroller/userlogin.do";
            var jsonstr = '{openid: "' + openid + '",nickname: "ceshi",sex: "1"}';
            $.ajax({
                url: url,
                type: 'post',
                dataType: "json",
                data: {
                    json: jsonstr
                },
                async: false,
                success: function (data) {
                    var upurl = $("#upurl").val();
                    if (isempty(upurl))
                        location.href = "/except/files/home_page.jsp";
                    else
                        location.href = upurl;
                },
                error: function (data) {
                    var upurl = $("#upurl").val();
                    if (isempty(upurl))
                        location.href = "/except/files/home_page.jsp";
                    else
                        location.href = upurl;
                }
            });
        }
    </script>
</head>

<body>
<jsp:include page="/public.jsp"/>
openid:<input id="openid"/>
<input type="hidden" value="<%=url%>" id="upurl"/>
<input type="hidden" value="<%=request.getParameter("type") + ""%>" id="logintype"/>
<button onclick="login();">登录</button>
</body>
</html>